var co = require('co');
var seqModule = require('../../models/index');
var db = new seqModule();
var util = require('../../common/util');
var buildController = {
    getbuild: function (req, res) {
        co(function () {
            var params = {};
            var paramT = {};
            var include = [];
            var includeParams= {model:db.meetSubjectModule};
            if(req.query.meetDate != undefined){
                includeParams.where = {'meetDate':req.query.meetDate};
            }
            include.push(includeParams);
            paramT.include = include;
            if (req.query.buildTitle != undefined) {
                params["buildTitle"] = { "$like": "%" + req.query.buildTitle + "%" };
            }
            if (req.query.meetId != undefined) {
                params["meetId"] = { "$like": "%" + req.query.meetId + "%" };
            }
            paramT["where"] = params;
            paramT["order"] =  [['code','ASC'],[ db.meetSubjectModule, 'startTime','ASC' ] ]
            if (req.query.page != undefined && req.query.rows != undefined) {
                paramT["offset"] = parseInt(req.query.page);
                paramT["limit"] = parseInt(req.query.rows);
            }
            db.buildModule.findAll(paramT).then(function (result) {
                res.status(200).json(result);
            });
        }).catch(function (e) {
            res.status(500).json({"message":"服务异常！"});
            console.log(e);
        })
    }
}
module.exports = buildController;